<?php
/**
 * IG_Acl_Resource
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Resource.php 232 2011-04-07 10:50:48Z mmxie $
 */
class IG_Acl_Resource extends Zend_Acl_Resource
{
    protected $_children = array();

    /**
     * 创建一个资源
     *
     * @param string $resourceId
     * @param array $child
     */
    public function __construct($resourceId, $child = null)
    {
        $this->_resourceId = (string) $resourceId;
        if ($child != null) {
            $this->_children = array($child);
        }
    }

    /**
     * 为资源添加一个子参数
     *
     * @param array $child
     */
    public function addChild($child)
    {
        if ($this->_children == null) {
            $this->_children = array($child);
        } else {
            $this->_children[] = $child;
        }
    }

    /**
     * 返回所有的子参数
     *
     * @return array
     */
    public function getChildren()
    {
        return $this->_children;
    }

    /**
     * 返回当前的子参数
     *
     * @return array
     */
    public function getCurrentChild()
    {
        if ($this->hasChildren()) {
            return $this->_children[0];
        }
    }

    /**
     * 判断是否定义了子参数
     *
     * return boolean
     */
    public function hasChildren()
    {
        return $this->_children !== null;
    }
}
